﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace Studio
{
	// Token: 0x02000507 RID: 1287
	public class UndoRedoManager : Singleton<UndoRedoManager>
	{
		// Token: 0x14000002 RID: 2
		// (add) Token: 0x060020C9 RID: 8393 RVA: 0x000CA440 File Offset: 0x000C8640
		// (remove) Token: 0x060020CA RID: 8394 RVA: 0x000CA478 File Offset: 0x000C8678
		public event EventHandler CanUndoChange;

		// Token: 0x14000003 RID: 3
		// (add) Token: 0x060020CB RID: 8395 RVA: 0x000CA4B0 File Offset: 0x000C86B0
		// (remove) Token: 0x060020CC RID: 8396 RVA: 0x000CA4E8 File Offset: 0x000C86E8
		public event EventHandler CanRedoChange;

		// Token: 0x170003DF RID: 991
		// (get) Token: 0x060020CD RID: 8397 RVA: 0x000CA520 File Offset: 0x000C8720
		// (set) Token: 0x060020CE RID: 8398 RVA: 0x000CA528 File Offset: 0x000C8728
		public bool CanUndo
		{
			get
			{
				return this.m_CanUndo;
			}
			private set
			{
				if (this.m_CanUndo != value)
				{
					this.m_CanUndo = value;
					if (this.CanUndoChange != null)
					{
						this.CanUndoChange(this, EventArgs.Empty);
					}
				}
			}
		}

		// Token: 0x170003E0 RID: 992
		// (get) Token: 0x060020CF RID: 8399 RVA: 0x000CA55C File Offset: 0x000C875C
		// (set) Token: 0x060020D0 RID: 8400 RVA: 0x000CA564 File Offset: 0x000C8764
		public bool CanRedo
		{
			get
			{
				return this.m_CanRedo;
			}
			private set
			{
				if (this.m_CanRedo != value)
				{
					this.m_CanRedo = value;
					if (this.CanRedoChange != null)
					{
						this.CanRedoChange(this, EventArgs.Empty);
					}
				}
			}
		}

		// Token: 0x060020D1 RID: 8401 RVA: 0x000CA598 File Offset: 0x000C8798
		public void Do(ICommand _command)
		{
			if (_command == null)
			{
				return;
			}
			this.undo.Push(_command);
			this.CanUndo = true;
			_command.Do();
			this.redo.Clear();
			this.CanRedo = false;
		}

		// Token: 0x060020D2 RID: 8402 RVA: 0x000CA5CC File Offset: 0x000C87CC
		public void Do(Delegate _doMethod, object[] _doParamater, Delegate _undoMethod, object[] _undoParamater)
		{
			UndoRedoManager.Command command = new UndoRedoManager.Command(_doMethod, _doParamater, _undoMethod, _undoParamater);
			this.Do(command);
		}

		// Token: 0x060020D3 RID: 8403 RVA: 0x000CA5EC File Offset: 0x000C87EC
		public void Do()
		{
			if (this.undo.Count <= 0)
			{
				return;
			}
			this.Do(this.undo.Peek());
		}

		// Token: 0x060020D4 RID: 8404 RVA: 0x000CA614 File Offset: 0x000C8814
		public void Undo()
		{
			if (this.undo.Count <= 0)
			{
				return;
			}
			ICommand command = this.undo.Pop();
			this.CanUndo = (this.undo.Count > 0);
			command.Undo();
			this.redo.Push(command);
			this.CanRedo = true;
		}

		// Token: 0x060020D5 RID: 8405 RVA: 0x000CA66C File Offset: 0x000C886C
		public void Redo()
		{
			if (this.redo.Count <= 0)
			{
				return;
			}
			ICommand command = this.redo.Pop();
			this.CanRedo = (this.redo.Count > 0);
			command.Redo();
			this.undo.Push(command);
			this.CanUndo = true;
		}

		// Token: 0x060020D6 RID: 8406 RVA: 0x000CA6C4 File Offset: 0x000C88C4
		public void Push(ICommand _command)
		{
			if (_command == null)
			{
				return;
			}
			this.undo.Push(_command);
			this.CanUndo = true;
			this.redo.Clear();
			this.CanRedo = false;
		}

		// Token: 0x060020D7 RID: 8407 RVA: 0x000CA6F4 File Offset: 0x000C88F4
		public void Clear()
		{
			this.undo.Clear();
			this.redo.Clear();
			this.CanUndo = false;
			this.CanRedo = false;
		}

		// Token: 0x060020D8 RID: 8408 RVA: 0x000CA71C File Offset: 0x000C891C
		protected override void Awake()
		{
			if (!base.CheckInstance())
			{
				return;
			}
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
		}

		// Token: 0x04002261 RID: 8801
		private Stack<ICommand> undo = new Stack<ICommand>();

		// Token: 0x04002262 RID: 8802
		private Stack<ICommand> redo = new Stack<ICommand>();

		// Token: 0x04002263 RID: 8803
		private bool m_CanUndo;

		// Token: 0x04002264 RID: 8804
		private bool m_CanRedo;

		// Token: 0x02000508 RID: 1288
		private class Command : ICommand
		{
			// Token: 0x060020D9 RID: 8409 RVA: 0x000CA738 File Offset: 0x000C8938
			public Command(Delegate _doMethod, object[] _doParamater, Delegate _undoMethod, object[] _undoParamater)
			{
				this.doMethod = _doMethod;
				this.doParamater = _doParamater;
				this.undoMethod = _undoMethod;
				this.undoParamater = _undoParamater;
			}

			// Token: 0x060020DA RID: 8410 RVA: 0x000CA760 File Offset: 0x000C8960
			public void Do()
			{
				this.doMethod.DynamicInvoke(this.doParamater);
			}

			// Token: 0x060020DB RID: 8411 RVA: 0x000CA774 File Offset: 0x000C8974
			public void Undo()
			{
				this.undoMethod.DynamicInvoke(this.undoParamater);
			}

			// Token: 0x060020DC RID: 8412 RVA: 0x000CA788 File Offset: 0x000C8988
			public void Redo()
			{
				this.doMethod.DynamicInvoke(this.doParamater);
			}

			// Token: 0x04002267 RID: 8807
			private Delegate doMethod;

			// Token: 0x04002268 RID: 8808
			private Delegate undoMethod;

			// Token: 0x04002269 RID: 8809
			private object[] doParamater;

			// Token: 0x0400226A RID: 8810
			private object[] undoParamater;
		}
	}
}
